<template>
  <div class="timeline">
    <ul>
      <li v-for="item in props.data" :key="item.id">
        <div class="item">
          <div class="time">{{ formatTime(item.createAt) }}</div>
          <div class="content">{{ item.content }}</div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script setup>
  const props = defineProps({
    data: Array,
  })

  const formatTime = v => {
    let date = new Date(v)
    return (
      date.getFullYear() +
      '-' +
      (date.getMonth() + 1) +
      '-' +
      (date.getDate() < 10 ? '0' + date.getDate() : date.getDate())
    )
  }
</script>

<style lang="less" scoped>
  @media only screen and (min-width: 991px) {
    .timeline {
      width: 100%;
      ul {
        li {
          position: relative;
          list-style-type: none;
          width: 2px;
          margin: 0 auto;
          padding-top: 65px;
          background: var(--text-bright);
          &:nth-child(odd) {
            .item {
              left: 50px;
            }
          }
          &:nth-child(even) {
            .item {
              width: 360px;
              left: -400px;
              div {
                text-align: right;
              }
              .time {
                &::after {
                  left: 245px;
                }
              }
            }
          }
          &::after {
            content: '';
            position: absolute;
            left: 50%;
            bottom: 0;
            transform: translateX(-50%);
            width: 15px;
            height: 15px;
            border-radius: 50%;
            background: inherit;
            z-index: 1;
            background: var(--text-accent);
          }
          .item {
            position: relative;
            bottom: -24px;
            width: 400px;
            padding: 15px;
            font-size: 14px;
            border-radius: 16px;
            .time {
              position: relative;
              font-size: 26px;
              font-weight: 500;
              color: var(--text-bright);
              &::after {
                content: '';
                position: absolute;
                bottom: -9px;
                left: 5px;
                width: 75px;
                height: 5px;
                border-radius: 5px;
                background: var(--main-gradient);
              }
            }
            .content {
              margin-top: 20px;
            }
          }
        }
      }
    }
  }
  @media only screen and (max-width: 990px) {
    .timeline {
      width: 100%;
      ul {
        li {
          position: relative;
          list-style-type: none;
          width: 2px;
          margin: 0 auto;
          padding-top: 35px;
          background: var(--text-bright);
          &:nth-child(odd) {
            .item {
              left: 20px;
              .time {
                &::after {
                  content: '';
                  position: absolute;
                  bottom: -9px;
                  left: 5px;
                  width: 75px;
                  height: 5px;
                  border-radius: 5px;
                  background: var(--main-gradient);
                }
              }
            }
          }
          &:nth-child(even) {
            .item {
              width: 200px;
              left: -220px;
              div {
                text-align: right;
              }
              .time {
                &::after {
                  content: '';
                  position: absolute;
                  bottom: -9px;
                  right: 5px;
                  width: 75px;
                  height: 5px;
                  border-radius: 5px;
                  background: var(--main-gradient);
                }
              }
            }
          }
          &::after {
            content: '';
            position: absolute;
            left: 50%;
            bottom: 0;
            transform: translateX(-50%);
            width: 16px;
            height: 16px;
            border-radius: 50%;
            background: inherit;
            z-index: 1;
            background: var(--text-accent);
          }
          .item {
            position: relative;
            bottom: -24px;
            width: 160px;
            padding: 10px;
            font-size: 12px;
            border-radius: 16px;
            .time {
              position: relative;
              font-size: 18px;
              font-weight: 500;
              color: var(--text-bright);
            }
            .content {
              margin-top: 20px;
            }
          }
        }
      }
    }
  }
</style>
